package cn.edu.lingnan.controller;

import cn.edu.lingnan.service.EmailService;
import cn.edu.lingnan.util.Generate;
import jakarta.mail.MessagingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class AuthController {
    @Autowired
    private EmailService emailService;
    @PostMapping("/send-code")
    public Result sendCode(@RequestParam String email) {
        
        String code = Generate.generateCode();
        try {
            emailService.sendCodeEmail(email, code);
            return Result.success();
        } catch (MessagingException e) {
            return Result.error("邮件发送失败");
        }
    }
}